﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="diem_add.aspx.cs" Inherits="VQWEB.administrator.huongnghiep.diem.diem_add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
    <form id="frmObjects" action="" method="post">
    <div id="col8" class="col-md-8"></div>
    <div id="col4" class="col-md-4"></div>
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/huongnghiep/diem/handler";
        var url_input = '<%=ResolveUrl("~/administrator/templates/input.tpl") %>';

        $(document).ready(function () {
            $.get(url_ashx, { view_diem: "view_diem", Id: GetId() }, function (data) {
                var parse = $.parseJSON(data);
                var truong = parse.truong;
                var nganh = parse.nganh;
                var array_truong, array_nganh;

                if (CheckAtionInPath("add")) {
                    array_truong = array_checkbox(truong);
                    array_nganh = array_checkbox(nganh);
                    loadform(0, "", "", "", "", "", false, array_truong, array_nganh);
                }
                else if (CheckAtionInPath("edit")) {
                    var diem = parse.diem;
                    var truong = parse.truong;
                    var nganh = parse.nganh;
                    array_truong = array_checkbox(truong);
                    array_nganh = array_checkbox(nganh);
                    loadform(diem.id,diem.nam, diem.chuan,diem.nv1, diem.nv2,diem.nv3, diem.active, array_truong, array_nganh);
                }
            });
        });

        function loadform(id, nam, chuan, nv1, nv2, nv3, active, array_truong, array_nganh) {
            $.jqoteload(url_input, function (tmpl) {
                $("#col4").multiple("groupcheckbox", null, array_nganh, "Nganh:", tmpl.input_tpl);
                $("#col4").multiple("groupcheckbox", null, array_truong, "truong:", tmpl.input_tpl);
                $("#col8").single("hidden", "diem_id", id, null, null, tmpl.input_tpl);
                $("#col8").single("text", "diem_nam", nam, "Năm:", null, tmpl.input_tpl);
                $("#col8").single("text", "diem_chuan", chuan, "Điểm chuẩn:", null, tmpl.input_tpl);
                $("#col8").single("text", "diem_nv1", nv1, "NV1:", null, tmpl.input_tpl);
                $("#col8").single("text", "diem_nv2", nv2, "NV2:", null, tmpl.input_tpl);
                $("#col8").single("text", "diem_nv3", nv3, "NV3:", null, tmpl.input_tpl);
                $("#col8").single("checkbox", "diem_active", true, "Kích hoạt", active, tmpl.input_tpl);
                $("#frmObjects").validate({
                    rules: { diem_nam: { required: true }, diem_chuan: {required:true} },
                    messages: { diem_nam: { required: null }, diem_chuan: { required: true} }
                });
            });

        }

      
        $(document).on("click", "#btnCancel", function () {
            window.location = "/admin/huongnghiep/diem/list";
        });
        $(document).on("click", "#btnSave", function () {
            if ($("#frmObjects").valid()) {
                var arr = $("#frmObjects").serializeObject();
                $.post(url_ashx, { add_diem: window.escape(arr) }, function (data) {
                    alert(data);
                    window.location = "/admin/huongnghiep/diem/list";
                });
            }
        });
    </script>
</asp:Content>